const dict = {
  data() {
    return {
      params: {},
      isEdit: ''
    }
  },
  methods: {
    add(title, groupId, parentKey) {
      this.title = title;
      this.isEdit = false
      this.params = {
        groupId: groupId,
        parentKey: parentKey
      }
      this.input = ''
      this.dialogVisible = true;
    },
    handleEdit(row, title) {
      this.params = row;
      this.input = row.dValue;
      this.title = title;
      this.dialogVisible = true;
      this.isEdit = true
    },
    handleDelete(row, callBack, id, list) {
      this.$confirm('此操作将删除该行信息, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.axios.delete(`/dict/${row.id}`).then((res) => {
            console.log(res)
            if (res.data.code == 200) {
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
              this[callBack](id, list)
            } else {
              this.$message({
                type: 'info',
                message: '删除失败！'
              });
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    },
    getGroup(id, list) {
      this.axios.get('/dict?groupId=' + id).then((res) => {
        console.log(res)
        if (res.data && res.data.data) {
          this[list] = res.data.data
          sessionStorage.setItem(list, JSON.stringify(res.data.data))
        } else {
          this.$message('系统繁忙，请稍后再试')
        }
      }).catch((err) => {
        console.log(err)
        this.$message('系统繁忙，请稍后再试')
      })
    }
  }
}

export default dict